import 'package:flutter/cupertino.dart';
import '../../../lib_baseview/widget/dialogs.dart';
import '../../../resource/language/generated/l10n.dart';
import '../interface/root_proxy_model.dart';

class RideUtil {
  static Future<bool> endDoufeng(BuildContext context) async {
    // EndReq endRideRequestReq = EndReq.create();
    // var userResponse = await AutoRideApi.instance.endRide(endRideRequestReq);
    // if (!userResponse.isSuccess) {
    //   showToast(T.current!
    //       .str(userResponse.errorMsg ?? T.current!.service_error_retry));
    //   return false;
    // } else {
    return true;
    // }
  }

  static Future<bool?> showEndRideDialog(BuildContext context) {
    return showNormalDialog(
        context: context,
        title: T.current.end_df,
        content: Text(T.current.end_df_tips),
        onConfirm: () => endDoufeng(context));
  }

  /// 退出兜风
  static Future<bool> checkEndRide(RootProxyModel rootModel) async {
    // if (rootModel.channel == null) return true;

    // if (rootModel.channel!.roomTypeObj.type == RoomType.JOY_RIDE &&
    //     !UserManager.instance.isSuperAdmin) {
    //   if (rootModel.meWithSlot?.micType == MicTypeEnum.CAR_OWNER_MIC) {
    //     var result = await RideUtil.showEndRideDialog(Get.context!);
    //     if (result == true) rootModel.release();
    //     return false;
    //   } else {
    //     // 车手是否在麦上
    //     var carOwnerOnMic = (rootModel.channel?.broadcaster
    //                 .firstWhereOrNull(
    //                     (_) => _.micType == MicTypeEnum.CAR_OWNER_MIC)
    //                 ?.user
    //                 .id
    //                 .toInt() ??
    //             0) >
    //         0;

    //     // 车手在麦上，嘉宾不允许退房
    //     if (carOwnerOnMic) {
    //       showToast(T.current!.cant_quit_df_playing);
    //       return false;
    //     } else {
    //       return true;
    //     }
    //   }
    // } else {
    return true;
  }
  // }
}
